import React, { useState } from "react";
import {
  MenuFoldOutlined,
  MenuUnfoldOutlined,
  UploadOutlined,
  UserOutlined,
  VideoCameraOutlined,
  SettingOutlined,
} from "@ant-design/icons";
import { Layout, Menu, Button, theme } from "antd";
import { NavLink, Outlet } from "react-router-dom";

const { Header, Sider, Content } = Layout;
const Index: React.FC = () => {
  const [collapsed, setCollapsed] = useState(false);
  const {
    token: { colorBgContainer, borderRadiusLG },
  } = theme.useToken();
  const items =
    localStorage.getItem("row") == "admin"
      ? [
          {
            key: "1",
            icon: <UserOutlined />,
            label: <NavLink to="/home/home">首页</NavLink>,
          },
          {
            key: "2",
            icon: <VideoCameraOutlined />,
            label: <NavLink to="/home/list">列表</NavLink>,
          },
          {
            key: "3",
            icon: <UploadOutlined />,
            label: <NavLink to="/home/updata">上传</NavLink>,
          },
          {
            key: "4",
            icon: <SettingOutlined />,
            label: <NavLink to="/home/set">设置</NavLink>,
          },
        ]
      : [
          {
            key: "1",
            icon: <UserOutlined />,
            label: <NavLink to="/home/home">首页</NavLink>,
          },
          {
            key: "2",
            icon: <VideoCameraOutlined />,
            label: <NavLink to="/home/list">列表</NavLink>,
          },
          {
            key: "3",
            icon: <UploadOutlined />,
            label: <NavLink to="/home/updata">上传</NavLink>,
          },
        ];
  return (
    <Layout>
      <Sider trigger={null} collapsible collapsed={collapsed}>
        <div className="demo-logo-vertical" />
        <Menu
          theme="dark"
          mode="inline"
          defaultSelectedKeys={["1"]}
          items={items}
        />
      </Sider>
      <Layout>
        <Header style={{ padding: 0, background: colorBgContainer }}>
          <Button
            type="text"
            icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
            onClick={() => setCollapsed(!collapsed)}
            style={{
              fontSize: "16px",
              width: 64,
              height: 64,
            }}
          />
          用户身份:
          {localStorage.getItem("row") == "admin"
            ? "管理员(admin)"
            : "普通用户(user)"}
        </Header>
        <Content
          style={{
            margin: "24px 16px",
            padding: 24,
            minHeight: 400,
            background: colorBgContainer,
            borderRadius: borderRadiusLG,
          }}
        >
          <Outlet />
        </Content>
      </Layout>
    </Layout>
  );
};
export default Index;
